export class Logger {
  constructor(env) {
    this.isDebug = env.DEBUG === 'true';
    this.module = '';
  }

  setModule(module) {
    this.module = module;
    return this;
  }

  formatMessage(level, message, data) {
    const timestamp = new Date().toISOString();
    const moduleInfo = this.module ? `[${this.module}]` : '';
    const dataStr = data ? `\nData: ${JSON.stringify(data, null, 2)}` : '';
    return `${timestamp} ${level}${moduleInfo}: ${message}${dataStr}`;
  }

  debug(message, data) {
    if (this.isDebug) {
      console.debug(this.formatMessage('DEBUG', message, data));
    }
  }

  info(message, data) {
    if (this.isDebug) {
      console.info(this.formatMessage('INFO', message, data));
    }
  }

  warn(message, data) {
    console.warn(this.formatMessage('WARN', message, data));
  }

  error(message, error, data) {
    const errorDetails = error ? `\nError: ${error.message}\nStack: ${error.stack}` : '';
    console.error(this.formatMessage('ERROR', `${message}${errorDetails}`, data));
  }
} 